home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / prsr_lib / cagd_wrt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-29  |  12.5 KB  |  295 lines

  1. /******************************************************************************
  2. * Cagd_Wrt.c - Generic Curve/Surface writing to files.                  *
  3. *******************************************************************************
  4. * Written by Gershon Elber, July. 90.                          *
  5. ******************************************************************************/
  6.  
  7. #ifdef USE_VARARGS
  8. #    include <varargs.h>
  9. #else
  10. #    include <stdarg.h>
  11. #endif /* USE_VARARGS */
  12.  
  13. #include <string.h>
  14. #include "prsr_loc.h"
  15. #include "irit_soc.h"
  16.  
  17. /*****************************************************************************
  18. * DESCRIPTION:                                                               M
  19. * Generic routine to write curve(s) to the given file.                 M
  20. *   If Comment is NULL, no comment is printed, if "" only internal comment.  M
  21. *                                                                            *
  22. * PARAMETERS:                                                                M
  23. *   Crvs:      To be saved in file f.                                        M
  24. *   FileName:  File name where output should go to.                          M
  25. *   Indent:    Column in which all printing starts at.                       M
  26. *   Comment:   Optional comment to describe the geometry.                    M
  27. *   ErrStr:    If failed, ErrStr will be set to describe the problem.        M
  28. *                                                                            *
  29. * RETURN VALUE:                                                              M
  30. *   int:        TRUE if succesful, FALSE otherwise.                          M
  31. *                                                                            *
  32. * KEYWORDS:                                                                  M
  33. *   CagdCrvWriteToFile, files, write                                         M
  34. *****************************************************************************/
  35. int CagdCrvWriteToFile(CagdCrvStruct *Crvs,
  36.                char *FileName,
  37.                int Indent,
  38.                char *Comment,
  39.                char **ErrStr)
  40. {
  41.     int RetVal = TRUE;
  42.     CagdCrvStruct *NextCrv;
  43.  
  44.     for (; Crvs != NULL && RetVal; Crvs = Crvs -> Pnext) {
  45.     NextCrv = Crvs -> Pnext;      /* To make sure we dump one at a time. */
  46.     Crvs -> Pnext = NULL;
  47.  
  48.     switch(Crvs -> GType) {
  49.         case CAGD_CBEZIER_TYPE:
  50.         RetVal = BzrCrvWriteToFile(Crvs, FileName, Indent,
  51.                        Comment, ErrStr);
  52.         break;
  53.         case CAGD_CBSPLINE_TYPE:
  54.         RetVal = BspCrvWriteToFile(Crvs, FileName, Indent,
  55.                        Comment, ErrStr);
  56.         break;
  57.         case CAGD_CPOWER_TYPE:
  58.         CAGD_FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  59.         default:
  60.         CAGD_FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  61.         return FALSE;
  62.     }
  63.  
  64.     Crvs -> Pnext = NextCrv;
  65.     }
  66.  
  67.     return RetVal;
  68. }
  69.  
  70. /*****************************************************************************
  71. * DESCRIPTION:                                                               M
  72. * Generic routine to write curve(s) to the given stream.             M
  73. *   If Comment is NULL, no comment is printed, if "" only internal comment.  M
  74. *                                                                            *
  75. * PARAMETERS:                                                                M
  76. *   Crvs:      To be saved in stream.                                        M
  77. *   Handler:   A handler to the open stream.                     M
  78. *   Indent:    Column in which all printing starts at.                       M
  79. *   Comment:   Optional comment to describe the geometry.                    M
  80. *   ErrStr:    If failed, ErrStr will be set to describe the problem.        M
  81. *                                                                            *
  82. * RETURN VALUE:                                                              M
  83. *   int:        TRUE if succesful, FALSE otherwise.                          M
  84. *                                                                            *
  85. * KEYWORDS:                                                                  M
  86. *   CagdCrvWriteToFile2, files, write                                        M
  87. *****************************************************************************/
  88. int CagdCrvWriteToFile2(CagdCrvStruct *Crvs,
  89.             int Handler,
  90.             int Indent,
  91.             char *Comment,
  92.             char **ErrStr)
  93. {
  94.     int RetVal = TRUE;
  95.     CagdCrvStruct *NextCrv;
  96.  
  97.     for (; Crvs != NULL && RetVal; Crvs = Crvs -> Pnext) {
  98.     NextCrv = Crvs -> Pnext;      /* To make sure we dump one at a time. */
  99.     Crvs -> Pnext = NULL;
  100.  
  101.     switch(Crvs -> GType) {
  102.         case CAGD_CBEZIER_TYPE:
  103.         RetVal = BzrCrvWriteToFile2(Crvs, Handler, Indent,
  104.                         Comment, ErrStr);
  105.         break;
  106.         case CAGD_CBSPLINE_TYPE:
  107.         RetVal = BspCrvWriteToFile2(Crvs, Handler, Indent,
  108.                         Comment, ErrStr);
  109.         break;
  110.         case CAGD_CPOWER_TYPE:
  111.         CAGD_FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  112.         return FALSE;
  113.         default:
  114.         CAGD_FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  115.         return FALSE;
  116.     }
  117.  
  118.     Crvs -> Pnext = NextCrv;
  119.     }
  120.  
  121.     return RetVal;
  122. }
  123.  
  124. /*****************************************************************************
  125. * DESCRIPTION:                                                               M
  126. * Generic routine to write curve(s) to the given file.                 M
  127. *   If Comment is NULL, no comment is printed, if "" only internal comment.  M
  128. *                                                                            *
  129. * PARAMETERS:                                                                M
  130. *   Crvs:      To be saved in file f.                                        M
  131. *   f:         File descriptor where output should go to.                    M
  132. *   Indent:    Column in which all printing starts at.                       M
  133. *   Comment:   Optional comment to describe the geometry.                    M
  134. *   ErrStr:    If failed, ErrStr will be set to describe the problem.        M
  135. *                                                                            *
  136. * RETURN VALUE:                                                              M
  137. *   int:        TRUE if succesful, FALSE otherwise.                          M
  138. *                                                                            *
  139. * KEYWORDS:                                                                  M
  140. *   CagdCrvWriteToFile3, files, write                                        M
  141. *****************************************************************************/
  142. int CagdCrvWriteToFile3(CagdCrvStruct *Crvs,
  143.             FILE *f,
  144.             int Indent,
  145.             char *Comment,
  146.             char **ErrStr)
  147. {
  148.     int Handler = IritPrsrOpenStreamFromFile(f, FALSE, FALSE, FALSE),
  149.     i = CagdCrvWriteToFile2(Crvs, Handler, Indent, Comment, ErrStr);
  150.  
  151.     IritPrsrCloseStream(Handler, TRUE);
  152.  
  153.     return i;
  154. }
  155.  
  156. /*****************************************************************************
  157. * DESCRIPTION:                                                               M
  158. * Generic routine to write surface(s) to the given file.             M
  159. *   If Comment is NULL, no comment is printed, if "" only internal comment.  M
  160. *                                                                            *
  161. * PARAMETERS:                                                                M
  162. *   Srfs:      To be saved in file f.                                        M
  163. *   FileName:  File name where output should go to.                          M
  164. *   Indent:    Column in which all printing starts at.                       M
  165. *   Comment:   Optional comment to describe the geometry.                    M
  166. *   ErrStr:    If failed, ErrStr will be set to describe the problem.        M
  167. *                                                                            *
  168. * RETURN VALUE:                                                              M
  169. *   int:        TRUE if succesful, FALSE otherwise.                          M
  170. *                                                                            *
  171. * KEYWORDS:                                                                  M
  172. *   CagdSrfWriteToFile, files, write                                         M
  173. *****************************************************************************/
  174. int CagdSrfWriteToFile(CagdSrfStruct *Srfs,
  175.                char *FileName,
  176.                int Indent,
  177.                char *Comment,
  178.                char **ErrStr)
  179. {
  180.     int RetVal = TRUE;
  181.     CagdSrfStruct *NextSrf;
  182.  
  183.     for (; Srfs != NULL && RetVal; Srfs = Srfs -> Pnext) {
  184.     NextSrf = Srfs -> Pnext;      /* To make sure we dump one at a time. */
  185.     Srfs -> Pnext = NULL;
  186.  
  187.     switch (Srfs -> GType) {
  188.         case CAGD_SBEZIER_TYPE:
  189.         RetVal = BzrSrfWriteToFile(Srfs, FileName, Indent,
  190.                        Comment, ErrStr);
  191.         break;
  192.         case CAGD_SBSPLINE_TYPE:
  193.         RetVal = BspSrfWriteToFile(Srfs, FileName, Indent,
  194.                        Comment, ErrStr);
  195.         break;
  196.         case CAGD_SPOWER_TYPE:
  197.         CAGD_FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  198.         return FALSE;
  199.         default:
  200.         CAGD_FATAL_ERROR(CAGD_ERR_UNDEF_SRF);
  201.         return FALSE;
  202.     }
  203.  
  204.     Srfs -> Pnext = NextSrf;
  205.     }
  206.  
  207.     return RetVal;
  208. }
  209.  
  210. /*****************************************************************************
  211. * DESCRIPTION:                                                               M
  212. * Generic routine to write surface(s) to the given stream.             M
  213. *   If Comment is NULL, no comment is printed, if "" only internal comment.  M
  214. *                                                                            *
  215. * PARAMETERS:                                                                M
  216. *   Srfs:      To be saved in stream.                                        M
  217. *   Handler:   A handler to the open stream.                     M
  218. *   Indent:    Column in which all printing starts at.                       M
  219. *   Comment:   Optional comment to describe the geometry.                    M
  220. *   ErrStr:    If failed, ErrStr will be set to describe the problem.        M
  221. *                                                                            *
  222. * RETURN VALUE:                                                              M
  223. *   int:        TRUE if succesful, FALSE otherwise.                          M
  224. *                                                                            *
  225. * KEYWORDS:                                                                  M
  226. *   CagdSrfWriteToFile2, files, write, stream                                M
  227. *****************************************************************************/
  228. int CagdSrfWriteToFile2(CagdSrfStruct *Srfs,
  229.             int Handler,
  230.             int Indent,
  231.             char *Comment,
  232.             char **ErrStr)
  233. {
  234.     int RetVal = TRUE;
  235.     CagdSrfStruct *NextSrf;
  236.  
  237.     for (; Srfs != NULL && RetVal; Srfs = Srfs -> Pnext) {
  238.     NextSrf = Srfs -> Pnext;      /* To make sure we dump one at a time. */
  239.     Srfs -> Pnext = NULL;
  240.  
  241.     switch (Srfs -> GType) {
  242.         case CAGD_SBEZIER_TYPE:
  243.         RetVal = BzrSrfWriteToFile2(Srfs, Handler, Indent,
  244.                         Comment, ErrStr);
  245.         break;
  246.         case CAGD_SBSPLINE_TYPE:
  247.         RetVal = BspSrfWriteToFile2(Srfs, Handler, Indent,
  248.                         Comment, ErrStr);
  249.         break;
  250.         case CAGD_SPOWER_TYPE:
  251.         CAGD_FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  252.         return FALSE;
  253.         default:
  254.         CAGD_FATAL_ERROR(CAGD_ERR_UNDEF_SRF);
  255.         return FALSE;
  256.     }
  257.  
  258.     Srfs -> Pnext = NextSrf;
  259.     }
  260.  
  261.     return RetVal;
  262. }
  263.  
  264. /*****************************************************************************
  265. * DESCRIPTION:                                                               M
  266. * Generic routine to write surface(s) to the given file.             M
  267. *   If Comment is NULL, no comment is printed, if "" only internal comment.  M
  268. *                                                                            *
  269. * PARAMETERS:                                                                M
  270. *   Srfs:      To be saved in file f.                                        M
  271. *   f:         File descriptor where output should go to.                    M
  272. *   Indent:    Column in which all printing starts at.                       M
  273. *   Comment:   Optional comment to describe the geometry.                    M
  274. *   ErrStr:    If failed, ErrStr will be set to describe the problem.        M
  275. *                                                                            *
  276. * RETURN VALUE:                                                              M
  277. *   int:        TRUE if succesful, FALSE otherwise.                          M
  278. *                                                                            *
  279. * KEYWORDS:                                                                  M
  280. *   CagdSrfWriteToFile3, files, write                                        M
  281. *****************************************************************************/
  282. int CagdSrfWriteToFile3(CagdSrfStruct *Srfs,
  283.             FILE *f,
  284.             int Indent,
  285.             char *Comment,
  286.             char **ErrStr)
  287. {
  288.     int Handler = IritPrsrOpenStreamFromFile(f, FALSE, FALSE, FALSE),
  289.     i = CagdSrfWriteToFile2(Srfs, Handler, Indent, Comment, ErrStr);
  290.  
  291.     IritPrsrCloseStream(Handler, TRUE);
  292.  
  293.     return i;
  294. }
  295.